package com.charlotte.study.gupao.flyweight.ticket;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author junjie.ding
 * @date 2020/3/10
 */
public class TrainTicketFactory {

    private static Map<String, ITicket> pool = new ConcurrentHashMap<>();

    public static ITicket getTrainTicket(String from, String to){

        if(!pool.containsKey(from + "->" + to)){
            System.out.println("没有找到票，新建票");
            ITicket ticket = new TrainTicket(from, to);
            pool.put(from + "->" + to, ticket);
        }
        return pool.get(from + "->" + to);
    }
}
